package hn.cch.client.configuration;

import hn.cch.common.exchange.ExchangeInterface;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.support.RestClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

@Configuration
public class ExchangeConfiguration {

    @Bean
    public ExchangeInterface getExchangeInterfaceProxy() {
        RestClient restClient = RestClient.create("http://localhost:8080");
        RestClientAdapter adapter = RestClientAdapter.create(restClient);
        HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
        return factory.createClient(ExchangeInterface.class);
    }
}
